/**
 * Project Name:rx-java
 * File Name:BufferDemo.java
 * Package Name:top.xiaocao.rx.java.filter.function
 * Date:2024年2月13日下午3:24:14
 * Copyright (c) 2024, zhengchong.wan@minicore.com.hk All Rights Reserved.
 *
*/

package top.xiaocao.rx.java.filter.function;

import java.util.List;

import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;

/**
 * @className:BufferDemo 
 * @comment: 注释信息 
 * @date:     2024年2月13日 下午3:24:14 
 * @author   zhengchong.wan
 * @since    V1.0.0	 
 */
public class BufferDemo {
	
	public static void main(String[] args) {
		 Observable.just("A", "B", "C", "D", "E")//这里演示发送5个事件
         .buffer(3, 2)//缓存列表数量为3个，步长为2
                .subscribe(new Observer<List<String>>() {
        @Override
        public void onSubscribe(Disposable d) {
            System.out.println("buffer：onSubscribe == 订阅");
        }
 
        @Override
        public void onNext(List<String> strings) {
        	System.out.println("buffer：onNext == 缓存事件数：" + strings.size());
            for (int j = 0; j < strings.size(); j++) {
            	System.out.println("buffer：子事件==" + strings.get(j));
            }
        }
 
        @Override
        public void onError(Throwable e) {
        	System.out.println("buffer：onError == " + e.getMessage());
        }
 
        @Override
        public void onComplete() {
        	System.out.println("buffer：onComplete == ");
        }
    });
	}

}

